package bank;

import javax.management.MBeanAttributeInfo;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

public class Atm extends JFrame {
    private ArrayList<User> users=new ArrayList();
    private Image backImg = Util.getImage("/images/background.jpg");
    private Login login = new Login(this);
    private Menu menu = new Menu(this);
    private SaveMoney saveMoney = new SaveMoney(this);
    private GetMoney getMoney = new GetMoney(this);
    private FindMoney findMoney = new FindMoney(this);
    private ModifyMoney modifyMoney =new ModifyMoney(this);
    private TransferMoney transferMoney=new TransferMoney(this);
    private int index;
    CardLayout cardLayout = new CardLayout();


    public Atm() {
        this.setContentPane(new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(backImg, 0, 0, 1000, 800, this);
            }
        });
        this.setLayout(cardLayout);
        init();


        this.add("login", login);
        this.add("menu", menu);
        this.add("saveMoney", saveMoney);
        this.add("getMoney", getMoney);
        this.add("findMoney", findMoney);
        this.add("modifyMoney",modifyMoney);
        this.add("transferMoney",transferMoney);


        this.setSize(1000, 800);
        this.setTitle("中国银行ATM机");
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    public void switchPanel(String name) {

        cardLayout.show(this.getContentPane(), name);
    }
public void init(){
        users=Util.query();
}
    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public FindMoney getFindMoney() {
        return findMoney;
    }

    public void setFindMoney(FindMoney findMoney) {
        this.findMoney = findMoney;
    }

    public ArrayList<User> getUsers() {
        return users;
    }

    public void setUsers(ArrayList<User> users) {
        this.users = users;
    }

    public Login getLogin() {
        return login;
    }

    public void setLogin(Login login) {
        this.login = login;
    }

    public static void main(String[] args) {
      new Atm();

    }

}
